package com.nasarius.bank.scorecard.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.nasarius.bank.scorecard.dao.AuthorityDAO;
import com.nasarius.bank.scorecard.domain.Authority;
import com.nasarius.bank.scorecard.domain.AuthorityExample;
@Repository
public class AuthorityDAOImpl extends SqlMapClientDaoSupport implements AuthorityDAO {

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table authorities
     *
     * @ibatorgenerated Sat Apr 09 15:48:39 IST 2011
     */
	@Autowired
    public AuthorityDAOImpl(/*@Qualifier("sqlMapClient")*/SqlMapClient sqlMapClient) {
        super();
        setSqlMapClient(sqlMapClient);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table authorities
     *
     * @ibatorgenerated Sat Apr 09 15:48:39 IST 2011
     */
    public int countAuthorityByExample(AuthorityExample example) {
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("authorities.ibatorgenerated_countByExample", example);
        return count;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table authorities
     *
     * @ibatorgenerated Sat Apr 09 15:48:39 IST 2011
     */
    public int deleteAuthorityByExample(AuthorityExample example) {
        int rows = getSqlMapClientTemplate().delete("authorities.ibatorgenerated_deleteByExample", example);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table authorities
     *
     * @ibatorgenerated Sat Apr 09 15:48:39 IST 2011
     */
    public void insertAuthority(Authority record) {
        getSqlMapClientTemplate().insert("authorities.ibatorgenerated_insert", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table authorities
     *
     * @ibatorgenerated Sat Apr 09 15:48:39 IST 2011
     */
    public void insertAuthoritySelective(Authority record) {
        getSqlMapClientTemplate().insert("authorities.ibatorgenerated_insertSelective", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table authorities
     *
     * @ibatorgenerated Sat Apr 09 15:48:39 IST 2011
     */
    @SuppressWarnings("unchecked")
    public List<Authority> selectAuthorityByExample(AuthorityExample example) {
        List<Authority> list = getSqlMapClientTemplate().queryForList("authorities.ibatorgenerated_selectByExample", example);
        return list;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table authorities
     *
     * @ibatorgenerated Sat Apr 09 15:48:39 IST 2011
     */
    public int updateAuthorityByExampleSelective(Authority record, AuthorityExample example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("authorities.ibatorgenerated_updateByExampleSelective", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table authorities
     *
     * @ibatorgenerated Sat Apr 09 15:48:39 IST 2011
     */
    public int updateAuthorityByExample(Authority record, AuthorityExample example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("authorities.ibatorgenerated_updateByExample", parms);
        return rows;
    }

    /**
     * This class was generated by Apache iBATIS ibator.
     * This class corresponds to the database table authorities
     *
     * @ibatorgenerated Sat Apr 09 15:48:39 IST 2011
     */
    private static class UpdateByExampleParms extends AuthorityExample {
        private Object record;

        public UpdateByExampleParms(Object record, AuthorityExample example) {
            super(example);
            this.record = record;
        }

        @SuppressWarnings("unused")
		public Object getRecord() {
            return record;
        }
    }

	@Override
	public int deleteAuthorityByPrimaryKey(String username) {
		Authority authority = new Authority();
		authority.setUsername(username);
        int rows = getSqlMapClientTemplate().delete("authorities.ibatorgenerated_deleteByPrimaryKey", authority);
        return rows;
	}
    @SuppressWarnings("unchecked")
	public List<Authority> selectAllUsers() {
        List<Authority> list = getSqlMapClientTemplate().queryForList("authorities.ibatorgenerated_selectAllUsers");
        return list;
	}
    
    public Authority selectUserAuthority(String username){
    	Authority authority = new Authority();
    	authority.setUsername(username);
    	Authority record = (Authority)getSqlMapClientTemplate().queryForObject("authorities.ibatorgenerated_selectUserAuthority", authority);
    	return record;
    }
    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table users
     *
     * @ibatorgenerated Sat Apr 09 15:48:39 IST 2011
     */
    public int updateAuthorityByUserName(Authority record) {
        int rows = getSqlMapClientTemplate().update("authorities.ibatorgenerated_updateAuthorityByUserName", record);
        return rows;
    }
}